package com.M.book.model;

import com.M.book.enums.ResultCode;
import lombok.Data;

@Data
//public class Result {
public class Result<T>{
    //业务状态码
    private ResultCode code;
    //错误信息
    private String errMsg;
    //数据
//    private Object data;
    private T data;

//    public static Result success(Object data) {
    public static <T> Result<T> success(T data) {
        Result result = new Result();
        result.setCode(ResultCode.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

//    public static Result fail(String errMsg) {
    public static <T> Result<T> fail(String errMsg) {
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }
//    public static Result fail(String errMsg, Object data) {
    public static <T> Result<T> fail(String errMsg, T data) {
        Result result = new Result();
        result.setCode(ResultCode.FAIL);
        result.setErrMsg(errMsg);
        result.setData(data);
        return result;
    }

//    public static Result unlogin() {
    public static <T> Result<T> unlogin(){
        Result result = new Result();
        result.setCode(ResultCode.UNLOGIN);
        result.setErrMsg("用户未登录");
        result.setData(null);
        return result;
    }
}
